package hotel.service.impl;

import hotel.service.IHotelOrderService;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import common.dao.HotelOrderDAO;
import common.pojo.HotelOrder;



@Scope("prototype")
@Service
public class HotelOrderService implements IHotelOrderService {
	@Autowired
	private HotelOrderDAO hotelOrderdao;
	
	public List<HotelOrder> find(String where){
		return hotelOrderdao.find(where);
	}
	
	public List<HotelOrder> find(int start, int limit,String orderbys, String where) {
		return hotelOrderdao.findList(start, limit, orderbys, where);
	}
	//统计，热销房间
	public List<HotelOrder> findHotList( String where,String where2,String count) {
		List<HotelOrder> resultlist=hotelOrderdao.findHotList(where,where2,count);
		for(int i=0,length=resultlist.size();i<length;i++){
			resultlist.get(i).setAll(hotelOrderdao.getCount(" roomStyleId="+resultlist.get(i).getRoomStyleId()));
			resultlist.get(i).setCancel(hotelOrderdao.getCount(" roomStyleId="+resultlist.get(i).getRoomStyleId()+"  and tradeStatus =5"));
		}
		return resultlist;
	}
	//查询
	public List<HotelOrder> findSearchList(String where) {
		List<HotelOrder> resultlist=hotelOrderdao.findSearchList(where);
		for(int i=0,length=resultlist.size();i<length;i++){
			resultlist.get(i).setAll(hotelOrderdao.getCount(" roomStyleId="+resultlist.get(i).getRoomStyleId()+" and "+where));
			resultlist.get(i).setCancel(hotelOrderdao.getCount(" roomStyleId="+resultlist.get(i).getRoomStyleId()+"  and tradeStatus =5 and "+where));
		}
		return resultlist;
	}
	
	public int getCount(String where){
		return hotelOrderdao.getCount(where);
	}
	
	public HotelOrder findInfoById(int id){
		return hotelOrderdao.findInfoById(id);
	}

	public HotelOrder findByCode(String orderCode) {
		return hotelOrderdao.findByCode(orderCode);
	}
	
	public boolean update(HotelOrder hotelOrder) {
		hotelOrderdao.update(hotelOrder);
		return true;
	}
	
	public boolean updateState(int id, int state) {
		hotelOrderdao.updateState(id, state);
		return true;
	}

	
	public boolean delete(String ids) {
		String[] id = StringUtils.split(ids,",");
		for(int i=0;i<id.length;i++){
			hotelOrderdao.delete(Integer.valueOf(id[i]));
		}
		return true;
	}

	public boolean verify(String ids) {
		String[] id=ids.split(",");
		for(int i=0;i<id.length;i++)
		{
			hotelOrderdao.verify(Integer.parseInt(id[i]));
		}
		return true;
	}

	public boolean save(HotelOrder order) {
		hotelOrderdao.save(order);
		return true;
	}

	public boolean updateReview(int orderid) {
		hotelOrderdao.updateReview(orderid);
		return true;
	}



}
